package com.jdk.demo.io.验证backlog;

import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	public static void main(String[] args) throws Exception {
		ServerSocket serverSocket = new ServerSocket(8888, 3);

		// 作用是不让ServerSocket调用accept方法，而是由客户端先发起10个请求，然后在执行accept方法时，只能接收到三个连接
		Thread.sleep(10000);

		System.out.println("accept1 begin");
		Socket socket1 = serverSocket.accept();
		System.out.println("accept1 end");

		System.out.println("accept2 begin");
		Socket socket2 = serverSocket.accept();
		System.out.println("accept2 end");

		System.out.println("accept3 begin");
		Socket socket3 = serverSocket.accept();
		System.out.println("accept3 end");

		System.out.println("accept4 begin");
		Socket socket4 = serverSocket.accept();
		System.out.println("accept4 end");

		System.out.println("accept5 begin");
		Socket socket5 = serverSocket.accept();
		System.out.println("accept5 end");

		socket1.close();
		socket2.close();
		socket3.close();
		socket4.close();
		socket5.close();
		serverSocket.close();
	}

}
